package org.huqiwen.blog.logic;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import org.huqiwen.blog.dao.DataSource;
import org.huqiwen.blog.data.BlogDataBean;
/**
 * 此类用来显示最近更新的文章列表，此类也可以不单独出来，可以将方法放到BlogLogicBean里面，
 * 但是考虑到结构清晰，还是单列出来了
 * @author Administrator
 *
 */
public class LastUpdateLogicBean {
	public List lastUpdateBlog(){
		List list = new ArrayList();
		Statement stmt = null;
		ResultSet rs = null; 		
		try {
			stmt = DataSource.getConnection().createStatement();
			rs = stmt.executeQuery("select * from posts order by id desc limit 5");
						
			while(rs.next()){	//将从数据中查询到数据存储到list中
				BlogDataBean bean = new BlogDataBean();
				bean.setBlogId(rs.getString(1));
				bean.setBlogTitle(rs.getString(2));
				list.add(bean);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			if (null!=stmt) {
				try {
					stmt.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (null!=rs) {
				try {
					rs.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}
		return list;
	}
}
